import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { EventName } from "../../../mvc/EventName";
import { GuildActivityConfigInfo } from "../../../resource/info/GuildActivityConfigInfo";
import { Language } from "../../../../../extend/language/Language";
import { GuildActivityType } from "../../../../../Message/Game/GuildActivityType";
import { Cache } from "../../../cache/Cache";
import { TaskTargetInfo } from "../../../model/TaskTargetInfo";
import { ENpcEffect } from "../../../../../Message/Public/ENpcEffect";
import { ObjCreate } from "../../common/ObjCreate";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { SecTimerView } from "../../common/SecTimerView";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { FlyFootBmp } from "../../mapUI/flyFoot/FlyFootBmp";
import { ImagesConst } from "../../../resource/ImagesConst";
import { DataEvent } from "../../../events/DataEvent";
import { ClockManager } from "../../../manager/ClockManager";
import { AIManager } from "../../../scene/ai/AIManager";
import { AIType } from "../../../scene/ai/AIType";
type int = number;
//class GuildActivityCellRenderer
    
    export  class GuildActivityCellRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.init();
            buttonMode = true;
            this.addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onMouseOverHandler);
            this.addEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onMouseOutHandler);
            Dispatcher.addEventListener(EventName.GuildActivityGetInfoSuccess, this.onGuildActivityGetInfoSuccessHandler);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            this._configInfo = arg1 as GuildActivityConfigInfo;
            if (this._configInfo) 
            {
                this._type = this._configInfo.type;
                this._nameTxt.text = this._configInfo.name;
                if (this._configInfo.type == 8 || this._configInfo.type == 9) 
                {
                    this._conditionTxt.htmlText = Language.getStringByParam(57594, this._configInfo.roleNeedLevel, this._configInfo.guildNeedLevel);
                }
                else 
                {
                    this._conditionTxt.htmlText = Language.getStringByParam(57499, this._configInfo.roleNeedLevel, this._configInfo.guildNeedLevel);
                }
                this._isLeftTime = this._configInfo.time == null;
                if (!this._isLeftTime) 
                {
                    this._timeTxt.text = this._configInfo.time;
                }
                if (this._type != GuildActivityType._EGuildActivityTypeGuildWar) 
                {
                    this._goTxt.htmlText = Language.getString(57500);
                    this._npcTarget = Cache.instance.scene.getGuildTaskNPC()[0] as TaskTargetInfo;
                }
                else 
                {
                    this._goTxt.htmlText = Language.getString(57501);
                    this._npcTarget = Cache.instance.scene.getNpcByEffect(ENpcEffect._ENpcGuildFightJoin);
                }
            }
            return;
        }

        /* internal  */init(): void
        {
            this.graphics.beginFill(0, 0);
            this.graphics.drawRect(0, 0, 435, 45);
            this.graphics.endFill();
            this.cacheAsBitmap = true;
            this._nameTxt = ObjCreate.createTextField("", 0, 10, 220, 20, this, new GTextFormat(FontUtil.songtiName, 12, 65280));
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._nameTxt.mouseEnabled = false;
            this._conditionTxt = ObjCreate.createTextField("", 85, 5, 220, 40, this);
            this._conditionTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._conditionTxt.mouseEnabled = false;
            this._timeTxt = new SecTimerView();
            this._timeTxt.setParse("HH: mm: ss");
            this._timeTxt.mouseEnabled = false;
            this._timeTxt.x = 160;
            this._timeTxt.y = 10;
            this._timeTxt.width = 175;
            this._timeTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._timeTxt.defaultTextFormat = GlobalStyle.textFormat6;
            this.addChild(this._timeTxt);
            this._goTxt = ObjCreate.createTextField("", 345, 10, 220, 20, this, new GTextFormat(FontUtil.songtiName, 12, 65280));
            this._goTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._goTxt.addEventListener(flash.events.TextEvent.LINK, this.onLinkClickHandler);
            this._flyFoot = new FlyFootBmp();
            this._flyFoot.x = 400;
            this._flyFoot.y = 10;
            this._flyFoot.addEventListener(flash.events.MouseEvent.CLICK, this.onFlyFootClickHandler);
            this.addChild(this._flyFoot);
            ObjCreate.createBg(10, 41, 435, 2, this, ImagesConst.SplitLine);
            this._selectLine = new Object /* flash.display.Sprite */();
            this._selectLine.mouseEnabled = false;
            this._selectLine.graphics.lineStyle(2, 65407, 1);
            this._selectLine.graphics.drawRoundRect(1, 0, 435, height - 2, 6, 6);
            this._selectLine.graphics.endFill();
            this._downLine = new Object /* flash.display.Sprite */();
            this._downLine.mouseEnabled = false;
            this._downLine.graphics.beginFill(880761, 1);
            this._downLine.graphics.lineStyle(2, 16744192, 0);
            this._downLine.graphics.drawRoundRect(1, 3, 435, 37, 6, 6);
            this._downLine.graphics.endFill();
            this._downLine.cacheAsBitmap = true;
            return;
        }

        public /* override */ set selected(arg1: Boolean)
        {
            super.selected = arg1;
            if (selected) 
            {
                if (this._downLine.parent == null) 
                {
                    addChildAt(this._downLine, 0);
                }
            }
            else if (this._downLine.parent) 
            {
                this._downLine.parent.removeChild(this._downLine);
            }
            return;
        }

        /* internal  */onMouseOverHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._selectLine.parent == null) 
            {
                addChildAt(this._selectLine, 0);
            }
            return;
        }

        /* internal  */onMouseOutHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._selectLine.parent) 
            {
                this._selectLine.parent.removeChild(this._selectLine);
            }
            return;
        }

        /* internal  */onGuildActivityGetInfoSuccessHandler(arg1: DataEvent): void
        {
            var loc2=null;
            var loc3=0;
            var loc4=null;
            var loc1=arg1.data as Map<any, any> /* flash.utils.Dictionary */;
            if (this._configInfo && this._isLeftTime && loc1) 
            {
                loc2 = loc1[this._configInfo.type];
                if (loc2) 
                {
                    loc4 = ClockManager.instance.nowDate;
                    loc3 = (loc2.startDt.time - loc4.time) / 1000;
                    this._isUnderWay = loc3 <= 0 && loc2.endDt.time - loc4.time > 0;
                    if (this._isUnderWay) 
                    {
                        this._timeTxt.htmlText = Language.getString(57509);
                    }
                    else 
                    {
                        this._timeTxt.setLeftTime(loc3);
                    }
                }
                else 
                {
                    this._timeTxt.text = Language.getString(90084);
                }
            }
            return;
        }

        /* internal  */onLinkClickHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            if (this._npcTarget) 
            {
                AIManager.onAutoPathAIControl(this._npcTarget);
            }
            return;
        }

        /* internal  */onFlyFootClickHandler(arg1: Object /* flash.events.Event */): void
        {
            if (this._npcTarget) 
            {
                AIManager.onAIControl(this._npcTarget, AIType.AI_Convey);
            }
            return;
        }

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_conditionTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_timeTxt: SecTimerView;

        /* internal */ /* var */_goTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_flyFoot: FlyFootBmp;

        /* internal */ /* var */_selectLine: Object /* flash.display.Sprite */;

        /* internal */ /* var */_downLine: Object /* flash.display.Sprite */;

        /* internal */ /* var */_configInfo: GuildActivityConfigInfo;

        /* internal */ /* var */_type: int;

        /* internal */ /* var */_isLeftTime: Boolean;

        /* internal */ /* var */_isUnderWay: Boolean;

        /* internal */ /* var */_npcTarget: TaskTargetInfo;
    }
